package morning.cat;

import morning.cat.config.ScanConfig;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

/**
 * @describe: 类描述信息
 * @author: morningcat.zhang
 * @date: 2020/1/6 11:04 AM
 * {https://blog.csdn.net/java_lyvee/article/details/101793774}
 */
public class Starter2 {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
		applicationContext.register(ScanConfig.class);
		//applicationContext.setAllowCircularReferences(false);
		// 完成 spring 容器的构建
		applicationContext.refresh();

		String[] beanDefinitions = applicationContext.getBeanDefinitionNames();
		Arrays.asList(beanDefinitions).forEach(System.out::println);
		System.out.println("---");
		for (String beanDefinitionName : beanDefinitions) {
			BeanDefinition beanDefinition = applicationContext.getBeanDefinition(beanDefinitionName);
			System.out.println(beanDefinition.getBeanClassName());
		}
		System.out.println("---");

//		UserService userService = applicationContext.getBean(UserService.class);
//		System.out.println(userService);

		System.out.println(applicationContext.getBean("userService"));
	}
}
